import frida
import sys

device = frida.get_usb_device()
pid = device.spawn("com.crackme.comingsoon")
session = device.attach(pid)
src = """
setImmediate(function(){
    Java.perform(function(){
        send("starting script");        
        var Activity = Java.use("com.crackme.comingsoon.WebviewActivity");
        var a = "aaaa";
        var b = "bbbbbbbbbbbbbbbbb";
        Activity.helloworld.implementation = function(a , b){

            var result = this.helloworld(a,b );
            send("helloworld = " + result);
            var newResult = "fadfas";
            send(newResult);
            return newResult;
        };   

    });
});
"""


def on_message(message, data):
    if message["type"] == "send":
        print("[+] {}".format(message["payload"]))
    else:
        print("[-] {}".format(message))


script = session.create_script(src)
script.on("message", on_message)
script.load()
device.resume(pid)
sys.stdin.read()
